﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">How can I prevent validation of required fields?</title>
  <keywords>
    <keyword translate="true">Data annotations</keyword>
    <keyword translate="true">FAQ</keyword>
    <keyword translate="true">Validation</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">How can I prevent validation of required fields?</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Catel does not validate the properties with data annotations at startup. It will only validate the data annotations when properties change or when the view model is about to be saved. This is implemented this way to allow a developer to show required fields with an asterisk (*) instead of errors. If a developer still wants to initially display errors, only a single call has to be made in the constructor:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">Validate(</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">true</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">, </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">false</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">If the validation is implemented in the models and not in the view model, set the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="P_Catel_MVVM_ViewModelBase_ValidateModelsOnInitialization" styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">ValidateModelsOnInitialization</link><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> to </text><text styleclass="Normal" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">false</text><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">.</text></para>
  </body>
</topic>
